﻿using AutoMapper;
using Domain.Entity.Config;
using Domain.Repository.IConfig;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CMController : Controller
    {
        private readonly IConfig_majorAppService cmAppService;
        private readonly IMapper mapper;

        public CMController(IConfig_majorAppService cmAppService, IMapper mapper)
        {
            this.cmAppService = cmAppService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }

        [HttpPost("GetCM")]
        public async Task<IActionResult> GetCM()
        {
            List<Config_major> cms=await cmAppService.GetCMAsync();
            return Json(cms);
        }

        [HttpPost("DeleteCM")]
        public async Task<IActionResult> DeleteCM(int id)
        {
            int i=await cmAppService.DeleteCMAsync(id);
            return Json(i);
        }
        [HttpPost("AddCM")]
        public async Task<IActionResult> AddCM(Config_major cm)
        {
            int i=await cmAppService.AddCMAsync(cm);
            return Json(i);
        }
        [HttpPost("GetCMById/{Id}")]
        public async Task<IActionResult> GetCMById(string id)
        {
            List<Config_major> cm=await cmAppService.GetCMAsyncById(id);
            return Json(cm);
        }
        [HttpPost("GetCMSById")]
        public async Task<IActionResult> GetCMSById(string id)
        {
            Config_major cm=await cmAppService.GetCMSAsyncById(id);
            return Json(cm);
        }
    }
}
